package jgl.vajra.kingkong.dialogFragment;

import android.content.Context;
import android.content.DialogInterface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.GridLayoutManager;

import java.util.ArrayList;
import java.util.List;

import jgl.vajra.kingkong.R;
import jgl.vajra.kingkong.databinding.DialogFragmentOrderDelayBinding;
import jgl.vajra.kingkong.databinding.DialogFragmentOrderDelayTimeBinding;
import jgl.vajra.kingkong.listener.OrderDelayedTimeListener;
import jgl.vajra.kingkong.widget.databindingadapter.BaseBindingItemPresenter;
import jgl.vajra.kingkong.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.kingkong.widget.dialogfragment.BaseDialogFragment;
import jgl.vajra.kingkong.widget.utils.ToastUtils;
import jgl.vajra.kingkong.widget.utils.UIUtils;

public class OrderDelayedTimeDialogFragment extends BaseDialogFragment<DialogFragmentOrderDelayTimeBinding> implements BaseBindingItemPresenter<String> {

    private OrderDelayedTimeListener listener;

    @Override
    public void initView(Context context, View rootView, AttributeSet attrs) {
        mBinding.setView(this);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetEdit);

        List<String> list = new ArrayList<>();

        for (int i = 1; i < 37; i++) {
            list.add(i + "小时");
        }


        // 不可嵌套滑动
        mBinding.recyclerView.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.recyclerView.setFocusableInTouchMode(false);
        //设置布局管理器
        mBinding.recyclerView.setLayoutManager(new GridLayoutManager(UIUtils.getContext(), 4));
        SingleTypeBindingAdapter adapter = new SingleTypeBindingAdapter(UIUtils.getContext(), list, R.layout.item_order_delayed_time);
        mBinding.recyclerView.setAdapter(adapter);
        adapter.setItemPresenter(this);
    }

    @Override
    public void initData(Context context) {
    }

    @Override
    public void initEvent(Context context) {

    }


    public int getLayoutRes() {
        return R.layout.dialog_fragment_order_delay_time;
    }


    @Override
    public int getGravity() {
        return Gravity.CENTER;
    }

    public void setOrderDelayedTimeListener(OrderDelayedTimeListener listener) {
        this.listener = listener;
    }

    //选择时间
    @Override
    public void onItemClick(int position, String itemData) {
        listener.onDetermine(position,itemData);
        dismiss();
    }
}